<template>
    <IDrawer v-model="defaultValue" :loading="loading" :width="860" title="添加客户">
        <Row>
            <BoxCell title="客户代码">{{data.code}}</BoxCell>
            <BoxCell title="客户名称">{{data.name}}</BoxCell>
            <BoxCell title="联系方式">{{data.phone}}</BoxCell>
            <BoxCell title="联系人">{{data.contacts}}</BoxCell>
            <BoxCell title="备注">{{data.remark}}</BoxCell>
            <BoxCell title="状态">
                <Tag v-if="data.status === 0">草稿</Tag>
                <Tag v-if="data.status === 1">审核中</Tag>
                <Tag v-if="data.status === 2">审核通过</Tag>
                <Tag v-if="data.status === 3">冻结</Tag>
                <Tag v-if="data.status === 4">审核驳回</Tag>
            </BoxCell>
        </Row>
        <Tabs value="name1">
            <TabPane label="日志" name="name1">
                <Logs v-model="data.logs"></Logs>
            </TabPane>
        </Tabs>
        <div slot="footer">
            <Button type="primary" v-if="data.status === 0" icon="ios-add" @click="submit">确认</Button>
            <Button type="primary" v-if="data.status === 1" icon="ios-add" @click="adopt">审核通过</Button>
            <PoptipRemark title="驳回" @on-submit="reject" v-if="data.status === 1"></PoptipRemark>
            <Button type="warning" icon="md-log-out" @click="defaultValue = false">返回</Button>
        </div>
    </IDrawer>
</template>

<script>
    import IDrawer from "../../../components/content/drawer";
    import contentDrawer from "../../../mixins/contentDrawer";
    import BoxCell from "../../../components/content/boxCell";
    import PoptipRemark from "../../../components/content/poptipRemark";
    import Logs from "../../../components/content/logs";

    export default {
        name: "show",
        mixins: [contentDrawer],
        components: {Logs, PoptipRemark, BoxCell, IDrawer},
        data() {
            return {
                data: {logs: []},
                loading: false
            }
        },
        mounted() {
            this.getData();
        },
        methods: {
            getData() {
                this.loading = true;
                this.$http.get(`customer/index/${this.props.id}`).then((res) => {
                    this.data = res
                    this.loading = false;
                }).finally(() => {
                    this.loading = false;
                });
            },
            submit() {
                this.loading = true;
                this.$http.put(`customer/${this.props.id}/submit`).then((res) => {
                    this.getData();
                }).finally(() => {
                    this.loading = false;
                });
            },
            reject(value) {
                this.loading = true;
                this.$http.put(`customer/${this.props.id}/reject`, {
                    value
                }).then((res) => {
                    this.getData();
                }).finally(() => {
                    this.loading = false;
                });
            },
            adopt() {
                this.loading = true;
                this.$http.put(`customer/${this.props.id}/adopt`).then((res) => {
                    this.getData();
                }).finally(() => {
                    this.loading = false;
                });
            }
        }
    }
</script>

<style scoped>

</style>